package lion.blog.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.apache.commons.lang.StringUtils;

import lion.blog.util.BlogUtil;
import lion.dev.io.FileUtil;
import lombok.Setter;

/**
 * 博客资源引用路径修正
 * <p>
 * 将路径修正到当前主题下面，如css,image,js文件
 * </p>
 * 
 * @author lion
 * @email hl_0074@sina.com
 * @date 2015年11月20日
 */
public class ResTag extends SimpleTagSupport {

	@Setter
	private String file;

	@Override
	public void doTag() throws JspException, IOException {

		if (StringUtils.isBlank(file)) { return; }

		String theme = BlogUtil.getCurrentTheme();

		PageContext pageContext = (PageContext) this.getJspContext();
		String context = pageContext.getServletContext().getContextPath();

		this.getJspContext().getOut().append(FileUtil.toUnixPath(context + "/res/blog/theme/" + theme + "/" + file));
	}
}
